<?php
$id = empty($_GET['id']) ? 0 : intval($_GET['id']);
if($id == 0){
	go('./');
}
$oAdvert = new Advert();
$advert = $oAdvert->get_row($id, '*');
if(empty($advert)){
	go('./');
}

if(empty($advert['related_goods']) && empty($advert['related_news']) && !empty($advert['url'])){
	go($advert['url']);
}

// 关联商品信息
if(empty($advert['related_goods'])){
	if(!empty($advert['related_news'])){
		$oGoods = new Goods();
		$goods_list = $oGoods->get_list('*', array('salesinfo' => $advert['related_news']), array('orderby_sales' => 'DESC', 'orderby_views' => 'DESC', 'id' => 'DESC'), 1, 16);
		foreach($goods_list['list'] as $key => $goods){
			if($__f_sysvars['url_rewrite'] == 'html' || $__f_sysvars['url_rewrite'] == 'rewrite'){
				if(empty($goods['filename'])){
					$goods['url'] = PUB_DIR.'goods/'.time_to_path($goods['addtime']).'/'.$goods['id'].'.html';
				}else{
					$goods['url'] = PUB_DIR.'goods/'.$goods['filename'].'.html';
				}
			}else{
				$goods['url'] = WEB_DIR."index.php?mdl=goods&do=view&id={$goods['id']}";
			}
			$goods_list['list'][$key] = $goods;
		}
		$advert['goods_list'] = $goods_list['list'];
	}
}else{
	$ids = explode(',', trim($advert['related_goods'], ', '));
	if(!isset($oGoods))$oGoods = new Goods();
	$advert['goods_list'] = array();
	foreach($ids as $goodsid){
		$goods = $oGoods->get_row($goodsid, '`id`,`name`,`cover`,`price`,`filename`,`recommend`,`addtime`');
		if($__f_sysvars['url_rewrite'] == 'html' || $__f_sysvars['url_rewrite'] == 'rewrite'){
			if(empty($goods['filename'])){
				$goods['url'] = PUB_DIR.'goods/'.time_to_path($goods['addtime']).'/'.$goods['id'].'.html';
			}else{
				$goods['url'] = PUB_DIR.'goods/'.$goods['filename'].'.html';
			}
		}else{
			$goods['url'] = WEB_DIR."index.php?mdl=goods&do=view&id={$goods['id']}";
		}
		$advert['goods_list'][$goodsid] = $goods;

	}
}

if(empty($advert['related_news'])){
	$advert['related_news'] = '';
}else{
	$oNews = new News();
	$advert['related_news'] = $oNews->get_row($advert['related_news'], '`id`,`content`');
}

$vars['advert'] = $advert;

/*******************************************************************************
 * 页面信息　& 当前位置
 *******************************************************************************/
if($__f_sysvars['url_rewrite'] == 'html' || $__f_sysvars['url_rewrite'] == 'rewrite'){
	url_here($advert['title'], $url = PUB_DIR."ads/{$brand["id"]}.html");
}else{
	url_here($advert['title'], $url = WEB_DIR."index.php?mdl=ads&id={$brand["id"]}");	
}
$__pageinfo['keywords'] = "{$brand['title']},{$brand['tags']}";
$__pageinfo['description'] = String::summary($brand['content'], 200);
?>